package com.cheetah.start.module.system.controller;

import com.cheetah.start.common.base.result.Result;
import com.cheetah.start.common.base.result.ResultController;
import com.cheetah.start.common.util.FileUtil;
import com.cheetah.start.module.system.domain.SysFile;
import com.cheetah.start.module.system.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Post;
import org.noear.solon.core.handle.UploadedFile;

import java.io.IOException;

@Slf4j
@Controller
@Mapping("/common")
public class CommonController extends ResultController {
    @Inject
    FileService fileService;

    /**
     * 上传
     *
     * @param file 文件
     * @return {@link Result}
     */
    @Post
    @Mapping("/upload")
    public Result upload(UploadedFile file) throws IOException {
        FileUtil.checkCommonSuffix(file);
        SysFile sysFile = fileService.uploadLocal(file);
        return success(sysFile);
    }
}
